/**
 * @author LKQ
 * @date 2022/1/9 16:05
 * @description
 */
public class Solution2 {
    public static void main(String[] args) {

    }
    public boolean searchMatrix(int[][] matrix, int target) {
        int m = matrix.length, n = matrix[0].length;
        for (int i = m - 1; i >= 0; i--) {
            if (matrix[i][0] <= target) {
                int left = 0, right = n-1;
                while (left <= right) {
                    int mid = (right - left) / 2 + left;
                    if (target == matrix[i][mid]) {
                        return true;
                    }else if (target > matrix[i][mid]) {
                        left = mid + 1;
                    }else {
                        right = mid - 1;
                    }
                }
            }
        }
        return false;
    }
}
